package com.smt.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zhangyi
 * @date 2018/10/19 17:29
 */
public class CheckUtil {

    public static final String MOBILE_REG = "^(((13[0-9])|(17([0-9]|[5-9]))|(15([0-9]|[5-9]))|(18[0-9,0-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$";

    public static final String EMAIL_REG = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    public static boolean checkPhone(String mobileNumber) {
        boolean flag = false;
        try {
            Pattern regex = Pattern.compile(MOBILE_REG);
            Matcher matcher = regex.matcher(mobileNumber);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }
    public static boolean checkEmail(String email) {
        boolean flag = false;
        try {
            Pattern regex = Pattern.compile(EMAIL_REG);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

}
